<template>
  <div>
    <div class="logo">
      <img src="@/assets/images/logo.png" />
      <h3>e店邦O2O平台</h3>
    </div>
    <el-menu active-text-color="rgb(64, 158, 255)" background-color="#304156" :default-active="defUrl"
      :class="{ 'el-menu--collapse': isCollapse }" :collapse="isCollapse" text-color="#fff" router>
      <el-menu-item index="/index">
        <el-icon><icon-menu /></el-icon>
        <span>首页</span>
      </el-menu-item>
      <el-sub-menu :index="item.path" v-for="item in store.menus" :key="item.name">
        <template #title>
          <i class="iconfont" :class="item.meta.icon"></i>
          <span>{{ item.meta.title }}</span>
        </template>

        <el-menu-item-group>
          <el-menu-item v-for="sub in item.children" :index="item.path + '/' + sub.path">{{
            sub.meta.title
          }}</el-menu-item>
        </el-menu-item-group>
      </el-sub-menu>
    </el-menu>
  </div>
</template>

<script lang="ts" setup>
import { inject, ref, watch } from "vue";
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from "@element-plus/icons-vue";
import { useUserStore } from "@/store/user";
import { getInfoApi } from "../api";
import { useRoute } from "vue-router";

const store = useUserStore();
const isCollapse = inject<boolean>("isCollapse");
const defUrl = ref("/index");
const route = useRoute();

watch(
  () => route.path,
  () => {
    defUrl.value = route.path;
  },
  {
    immediate: true,
  }
);
console.log(store.menus);

getInfoApi();


</script>

<style scoped lang="less">
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;

  h3 {
    height: 50px;
    font-size: 14px;
    line-height: 50px;
    color: #fff;
  }

  img {
    width: 32px;
    height: 32px;
    margin-right: 10px;
  }
}
</style>
